﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using motelmanagement.common;
using System.Data;
using System.Data.OleDb;
namespace motelmanagement.dao
{
    class RoomPriceDetailDAO
    {
        SqlUtil sqlUtil = new SqlUtil();
        OleDbCommand cmd = null;
        private string strSql = null;

        public DataTable getAllRoomPriceDetail() {
            strSql = "SELECT Room_price_detail.room_pri_dt_id, Room_price_detail.room_pri_dt_name";
            strSql += ", Room_price_detail.room_pri_dt_price, Room_price_detail.room_price_id, Room_price.room_price_name";
            strSql+=" FROM Room_price INNER JOIN Room_price_detail ON Room_price.room_price_id = Room_price_detail.room_price_id";
            sqlUtil.Load(cmd);
            return sqlUtil;
        }
        public DataTable getRoomPriceDetail(int id)
        {
            strSql = "SELECT Room_price_detail.room_pri_dt_id, Room_price_detail.room_pri_dt_name";
            strSql += " , Room_price_detail.room_pri_dt_price, Room_price_detail.room_price_id, Room_price.room_price_name";
            strSql += " FROM Room_price INNER JOIN Room_price_detail ON Room_price.room_price_id = Room_price_detail.room_price_id";
            strSql += " Where Room_price_detail.room_pri_dt_id=@id";
            cmd.Parameters.Add("id",SqlDbType.Int).Value=id;
            sqlUtil.Load(cmd);
            return sqlUtil;
        }
        public void insertRoomPriceDetail(string roomPriceDtName,int roomPriceDtPrice,int roomPriceId) {
            strSql += "Insert Into Room_price_detail(room_pri_dt_name,room_pri_dt_price,room_price_id)";
            strSql += " Values(@name,@price,@id)";
            cmd = new OleDbCommand(strSql);
            cmd.Parameters.Add("name", SqlDbType.NText).Value = roomPriceDtName;
            cmd.Parameters.Add("price", SqlDbType.Int).Value = roomPriceDtPrice;
            cmd.Parameters.Add("id", SqlDbType.Int).Value = roomPriceId;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
        public void updateRoomPriceDetail(int roomPriceDtId,string roomPriceDtName, int roomPriceDtPrice, int roomPriceId)
        {
            strSql += "Update Room_price_detail Set room_pri_dt_name=@name,room_pri_dt_price=@price,room_price_id=@id)";
            strSql += " Where room_pri_dt_id=@dtId";
            cmd = new OleDbCommand(strSql);
            cmd.Parameters.Add("name", SqlDbType.NText).Value = roomPriceDtName;
            cmd.Parameters.Add("price", SqlDbType.Int).Value = roomPriceDtPrice;
            cmd.Parameters.Add("id", SqlDbType.Int).Value = roomPriceId;
            cmd.Parameters.Add("dtid", SqlDbType.Int).Value = roomPriceDtId;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
        public void deleteRoomPriceDetail(int id) {
            cmd = new OleDbCommand("Delete From Room_price_detail Where room_pri_dt_id = @id");
            cmd.Parameters.Add("id", SqlDbType.Int).Value = id;
        }
    }
}
